import router from '~/router'
import { getToken } from '~/composables/auth'
import { toast } from '~/composables/util'
import store from '../store'
//全局前置守卫
router.beforeEach(async (to, from, next) => {
    const token = getToken()
    //没有登录强制跳转回登录页
    if (!token&&to.path != "/" && !to.path.includes('/login')) {  //to.path为当前路径
        
            toast("请先登录", "error")
            return next({ path: "/" })
       
    }
    //防止重复登录
    if (token && to.path.includes('/login')) {
        toast("请勿重复登录", "warning")
        return next({ path: from.path ? from.path : "/home" })
    }
    next()
})
